package utile;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * @author gzp
 * @create 2023-01-01 21:07
 */
public class Md5 {

    private String password;

    public Md5(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Md5() {
    }

    //完成对MD5算法的书写
    public String encryption(String s) {
        byte[] old = s.getBytes();
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
            byte[] newbytes = md.digest(old);
            Base64.Encoder encoder = Base64.getEncoder();
            String newstr = encoder.encodeToString(newbytes);
            return newstr;
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
}
